<template>
    <div class="nav-bar">
        <el-tabs
            v-model="activeTab"
            type="card"
            addable
            class="demo-tabs"
            @tab-click="handleJump"
            @tab-remove="handleRemove"
            >
            <!-- 自定义右侧添加的图标 -->
            <template #add-icon>
            <el-dropdown @command="handleDropDown">
                <el-icon>
                <arrow-down />
                </el-icon>
                <template #dropdown>
                <el-dropdown-menu>
                    <el-dropdown-item command="current">关闭当前标签页</el-dropdown-item>
                    <el-dropdown-item command="other">关闭其它标签页</el-dropdown-item>
                    <el-dropdown-item command="all">关闭全部标签页</el-dropdown-item>
                </el-dropdown-menu>
                </template>
            </el-dropdown>
            </template>

            <el-tab-pane
            v-for="(item, index) in store.tabs"
            :closable="index !== 0"
            :key="item.path"
            :label="item.title"
            :name="item.path"
            >
            </el-tab-pane>
        </el-tabs>
    </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import type { TabsPaneContext } from 'element-plus';
import useTabsStore from '../store/tabs';


  const store = useTabsStore()
  const router = useRouter()
  // const route = useRoute()



  const editableTabsValue = ref('1')

  const handleJump = (pane:TabsPaneContext)=>{
    // console.log(pane)
    router.push(pane.props.name)
  }
  const handleRemove = (path:string)=>{
    store.removeTab(path);
  }
  const handleDropDown = (command: string)=>{
    store.removeByCommand(command);
  }
</script>

<style scoped>

</style>
